package com.xianyun.book.domain.order;

import com.alibaba.cola.exception.BizException;

/**
 * @author ytt
 */
public enum OrderStatus {
    /**待售出*/
    WAIT_SOLD(OrderType.SELLER,0),
    /**待匹配*/
    WAIT_MATCH(OrderType.BUYER,1),
    /**待确认*/
    WAIT_CONFIRM(OrderType.BUYER,2),
    /**待发货*/
    WAIT_SHIP(null,3),
    /**以发货*/
    HAVE_SHIP(null,4),
    /**待配送*/
    WAIT_DELIVER(null,5),
    /**待收货*/
    WAIT_RECEIVE(null,6),
    /**已完成*/
    HAVE_FINISH(null,7),
    /**取消订单*/
    CANCEL(null,8);

    /**null 为共有属性 其余的为对应类型属性*/
    private OrderType belongType;
    private Integer statusId;

    OrderStatus(OrderType belongType, Integer statusId) {
        this.belongType = belongType;
        this.statusId = statusId;
    }

    public OrderType getBelongType() {
        return belongType;
    }

    public void setBelongType(OrderType belongType) {
        this.belongType = belongType;
    }

    public Integer getStatusId() {
        return statusId;
    }

    public static OrderStatus initOrderStatusById(Integer id){
        for (OrderStatus orderStatus: values()){
            if (orderStatus.getStatusId().equals(id)){
                return orderStatus;
            }
        }
        throw new BizException("OrderStatus不存在！");
    }
}
